# -*- coding:utf-8 -*-
import xlrd, os
from config import globalparam

data_path = globalparam.DATA_DIR


# 获取xlsx文件的数据,并返回一个list
def get_xlsx_to_list(excle_name, sheet_index=0):
    datapath = os.path.join(data_path, excle_name)
    excel = xlrd.open_workbook(datapath)
    table = excel.sheet_by_index(sheet_index)
    results = [table.row_values(i) for i in range(1, table.nrows)]

    return results


# 获取xlsx文件的数据,并返回一个dirt
def get_xlsx_to_dirt(excle_name, sheet_index=0):
    datapath = os.path.join(data_path, excle_name)
    excel = xlrd.open_workbook(datapath)
    table = excel.sheet_by_index(sheet_index)
    data_results = [table.row_values(i) for i in range(0, table.nrows)]
    results = [dict(zip(data_results[0], data_results[i])) for i in range(1, len(data_results))]

    return results
